<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace addons\video\model;

/**
 * Description of video
 * 视频
 * @author zmh
 */
class VideoTagsLike extends \web\common\model\BaseModel{
    
    protected $rows = 10;
    protected function _initialize(){
        $this->tableName = 'video_tags_like';
    }

    /**
     * 获取记录总数
     * @param type $filter
     * @return int
     */
    public function getTotal($filter = '') {
        $sql = 'select count(id) as c from '.$this->getTableName();
        if (!empty($filter)){
            $sql = $sql . ' where 1=1 ' . $filter;
        }
        $result = $this->query($sql);
        if (count($result) > 0)
            return intval($result[0]['c']);
        else
            return 0;
    }


    public function getDataList($pageIndex = -1, $pageSize = -1, $filter = '',$fileds='*', $order = 'id desc') {
        $sql = 'select * from '.$this->getTableName() . ' where 1=1 '.$filter;
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }


    /**
     * 喜欢视频
     */
    public function likeTags($user_id,$tags_id,$delete=0){
        $data = ['user_id'=>$user_id,'tags_id'=>$tags_id];
        if($delete == 0){
            $r = $this->where($data)->delete();
        }else{
            $data['create_time'] = NOW_DATETIME;
            $r = $this->add($data);
        }
        return $r;
    }
    
}
